using UnityEngine;
using System.Collections;

[System.Serializable]
public class AddDefenseShell : CharacterAction {
	public GameObject DefenseShell;
	public float durationTime = 10.0f;
	public GameObject DefenseShellPrefab;
	public float scale = 1.0f;
	public float height;

	// Update is called once per frame
	void BeginFade()
	{
		Destroy(DefenseShell);
		if(character.bodyState == BodyState.Armor)
		{
			character.bodyState = BodyState.Normal;
		}
	}

	void OnDestroy()
	{
		if(DefenseShell != null)
		{
			CancelInvoke("BeginFade");
			Destroy(DefenseShell);

		}
	}

	public override void OnActionEnter(Character character)
	{
		DefenseShell = (GameObject)Instantiate(DefenseShellPrefab);
		DefenseShell.transform.localScale = DefenseShell.transform.localScale * scale;
		DefenseShell.transform.parent = character.transform;
		DefenseShell.transform.localPosition = new Vector3(0,character.transform.position.y + height,0);
		character.bodyState = BodyState.Armor;
		Invoke("BeginFade",durationTime);	
	}

}
